<?php
require('../global.php');
?>
<!DOCTYPE html>
<html>
<head>
    <?php require('admin/_head.php'); ?>
    <title>管理控制台 - <?php echo getconfig('title'); ?>管理后台</title>
    <base target="_blank">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="alert alert-success alert-dismissable">
                    <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                    <i class="fa fa-magic"></i> 注意到顶部的标签了么？当你每打开一个新板块，就会在顶部新增一个标签，你可以通过切换标签来切换显示页面，双击标签可以刷新页面哦。
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-8">
                <div id="memberCard" class="ibox float-e-margins">
                    <?php
                        $admin = $db->get('tb_admin', '*', array('tbid' => session('admin_id')));
                        $admin['avatar'] = file_exists('uploads/admin/'.session('admin_id').'/avatar.jpg') ? SITEROOTURL.'uploads/admin/'.session('admin_id').'/avatar.jpg' : 'img/avatar.jpg';
                        /*$loginlog = $db->get('tb_admin_member_login_log', '*', array(
                            'AND' => array(
                                'admin_member_id' => session('admin_id'),
                                'createtime[<]' => $db->get('tb_admin_member_login_log', 'createtime', array(
                                    'admin_member_id' => session('admin_id'),
                                    'ORDER' => array(
                                        'createtime' => 'DESC'
                                    )
                                ))
                            ),
                            'ORDER' => array(
                                'createtime' => 'DESC'
                            )
                        ));
                        $ip = json_decode(file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.long2ip($loginlog['ip'])));
                        if($ip->code == '1'){
                            $loginlog['info'] = 'N/A';
                        }else{
                            $loginlog['info'] = $ip->data->region.$ip->data->city;
                        }*/
                    ?>
                    <div class="ibox-title">
                        <h3>我的信息</h3>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-xs-2 text-center">
                                <img alt="头像" class="img-circle img-hdicon m-b-sm" src="<?php echo $admin['avatar']; ?>" height="64" width="64">
                                <h4>嗨，<?php echo $admin['username']; ?></h4>
                                <small>欢迎回来 !</small>
                            </div>
                            <div class="col-xs-5" style="margin-top:10px">
                                <h5>本次登录信息：</h5>
                                <h2 class="city" style="padding-left:20px">加载中...</h2>
                                <font style="padding-left:20px">( IP地址：<span class="ip">加载中...</span> )</font>
                            </div>
                            <!-- <div class="col-xs-5" style="margin-top:10px">
                                <h5>上次登录信息：</h5>
                                <div class="m-b-xs">
                                    <small><i class="fa fa-fw fa-map-marker"></i> <?php echo $loginlog['info']; ?></small>
                                </div>
                                <div class="m-b-xs">
                                    <small><i class="fa fa-fw fa-clock-o"></i> <?php echo $loginlog['createtime']; ?></small>
                                </div>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <small>如果不是你登录，请立即</small>
                                        <a href="javascript:;" class="btn btn-default btn-xs" onclick="javascript:parent.outsideMenuItem('modue/personal/password.php', '修改密码');">修改密码</a>
                                    </div>
                                </div>
                            </div> -->
                        </div>
                    </div>
                </div>
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h3>会员分析</h3>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-4">
                                <div id="echarts_member_sex" style="height:200px"></div>
                            </div>
                            <div class="col-sm-8">
                                <div id="echarts_member_age" style="height:200px"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h3>快捷入口</h3>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-xs-6">
                                <a href="javascript:;" class="btn btn-default btn-md btn-outline btn-block" onclick="javascript:parent.outsideMenuItem('module/member/index.php', '会员管理');"><i class="fa fa-plus"></i> 会员管理</a>
                            </div>
                            <div class="col-xs-6">
                                <a href="javascript:;" class="btn btn-default btn-md btn-outline btn-block" onclick="javascript:parent.outsideMenuItem('module/testResult/index.php', '测试结果');"><i class="fa fa-user-plus"></i> 测试结果</a>
                            </div>
                           
                            <div class="col-xs-6">
                                <a href="javascript:;" class="btn btn-default btn-md btn-outline btn-block" onclick="javascript:parent.outsideMenuItem('module/expert/index.php', '专家名单');"><i class="fa fa-picture-o"></i> 专家名单</a>
                            </div>
                            
                        </div>
                    </div>
                </div>
                <div id="dataCard" class="ibox float-e-margins">
                    <div class="ibox-title">
                        <div class="row">
                            <div class="col-xs-7">
                                <h3>数据情报</h3>
                            </div>
                            <div class="col-xs-5">
                                <select class="form-control choose">
                                    <option value="1">今天 - 昨天</option>
                                    <option value="2">本周 - 上周</option>
                                    <option value="3">本月 - 上月</option>
                                    <option value="4">今年 - 去年</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="ibox-content data_info"></div>
                    <script id="dataTemp" type="text/html">
                        <div class="row regist">
                            <div class="col-xs-4">
                                <small><span><%= this_title %></span>测试人数</small>
                                <h3><%= regist[0] %></h3>
                            </div>
                            <div class="col-xs-4">
                                <small><span><%= that_title %></span>测试人数</small>
                                <h4><%= regist[1] %></h4>
                            </div>
                            <div class="col-xs-4">
                                <small>对比</small>
                                <h4>
                                    <strong class="<% if(regist[2] > 0){ %>text-success<% }else if(regist[2] < 0){ %>text-danger<% } %>"><span><%= regist[2] %></span>% <i class="fa <% if(regist[2] > 0){ %>fa-level-up<% }else if(regist[2] < 0){ %>fa-level-down<% } %>"></i></strong>
                                </h4>
                            </div>
                        </div>
                        <div class="row pv">
                            <div class="col-xs-4">
                                <small><span><%= this_title %></span>今日预约人数</small>
                                <h4><%= pv[0] %></h4>
                            </div>
                            <div class="col-xs-4">
                                <small><span><%= that_title %></span>今日预约人数</small>
                                <h4><%= pv[1] %></h4>
                            </div>
                            <div class="col-xs-4">
                                <small>对比</small>
                                <h4>
                                    <strong class="<% if(pv[2] > 0){ %>text-success<% }else if(pv[2] < 0){ %>text-danger<% } %>"><span><%= pv[2] %></span>% <i class="fa <% if(pv[2] > 0){ %>fa-level-up<% }else if(pv[2] < 0){ %>fa-level-down<% } %>"></i></strong>
                                </h4>
                            </div>
                        </div>
                        
                    </script>
                </div>
            </div>
        </div>
    </div>
    <?php require('admin/_js.php'); ?>
    <script src="http://pv.sohu.com/cityjson?ie=utf-8" charset="utf-8"></script>
    <!-- 自定义js -->
    <script src="<?php echo SITEROOTURL; ?>/admin/js/content.js?v=1.0.0"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/echarts/echarts.min.js" charset="utf-8"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/arttemplate/template.js"></script>
    <script type="text/javascript">
        $(function(){
            if(returnCitySN != undefined){
                $('#memberCard .city').text(returnCitySN.cname);
                $('#memberCard .ip').text(returnCitySN.cip);
            }
            $('#dataCard select.choose').change(function(event) {
                var type = $(this).val();
                $.ajax({
                    type: 'GET',
                    url: 'main.ajax.php',
                    dataType: 'json',
                    data: {
                        ac: 'data_info',
                        type: type
                    }
                }).done(function(cb){
                    $('#dataCard .data_info').html(template('dataTemp', cb));
                });
            });
            $('#dataCard select.choose').change();
            var echarts_member_sex = echarts.init(document.getElementById('echarts_member_sex'));
            $.ajax({
                type: 'GET',
                url: 'main.ajax.php',
                dataType: 'json',
                data: {
                    ac: 'echarts_member_sex'
                }
            }).done(function(cb){
                echarts_member_sex.setOption({
                    title: {
                        text: '性别',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a}<br>{b}：{c}人 ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['男','女']
                    },
                    series: [
                        {
                            name: '性别统计',
                            type: 'pie',
                            radius : '40%',
                            data: cb.sort(function (a, b) { return a.value - b.value; }),
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
            });
            var echarts_member_age = echarts.init(document.getElementById('echarts_member_age'));
            $.ajax({
                type: 'GET',
                url: 'main.ajax.php',
                dataType: 'json',
                data: {
                    ac: 'echarts_member_age'
                }
            }).done(function(cb){
                echarts_member_age.setOption({
                    title: {
                        text: '年龄',
                        left: 'center',
                        top: 0,
                        textStyle: {
                            color: '#666'
                        }
                    },
                    color: ['#3398DB'],
                    tooltip : {
                        trigger: 'axis',
                        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '3%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type : 'category',
                            data : ['7周岁', '8周岁', '9周岁', '10周岁', '11周岁', '12周岁', '13周岁'],
                            axisTick: {
                                alignWithLabel: true
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ],
                    series : [
                        {
                            name: '统计',
                            type: 'bar',
                            barWidth: '60%',
                            data: cb
                        }
                    ]
                });
            });
        });
    </script>
</body>
</html>
